
var nodemailer = require('nodemailer')
var credentials = require('../config/credentials')

// function sendMail(){

//     mailTransport.sendMail({
//         from:'zhou.xu@cloudcar.com',
//         to: 'joecustomer@gmail.com',
//         subject: 'welcom',
//         text:'欢迎使用Express'
//     },function(err){
//         if(err){
//             console.log('Unable to send mail: '+err);
//         }
//     })
// }


module.exports = function(credentials){


    var mailTransport = nodemailer.createTransport('SMTP',{
        service: 'Gmail',
        auth: {
            user: credentials.gamil.user,
            pass: credentials.gamil.password
        }
    });
    
    var from = 'zhou@cloudcar.com';

    return {

        send: function(to,subj,body){

            mailTransport.sendMail({

                from: from,
                to: to,
                subject: subj,
                html: body,
                genrarteTextFromHtml: true

            },function(err){
                if(err){
                    console.log('Unable to send mail: '+err);
                }
            })
        }
    }
    
}


// var mailTool = require('./mailTool')(credentials);

// mailTool.send('wang@gmail.com','请假1天','Get \'em while they\'re hot!');





